package com.car.dao.impl;

import com.car.dao.UserCarDao;
import com.car.domain.UserCar;
import com.car.utils.JDBCUtils;

import java.beans.JavaBean;
import java.util.List;

public class UserCarDaoImpl implements UserCarDao {
    @Override
    public int add(UserCar userCar) throws Exception {
        String sql="insert into t_user_car(user_id,car_id)"+
                " values(?,?)";
        return JDBCUtils.update(sql,userCar.getCarId(),userCar.getCarId());
    }

    @Override
    public int delete(int id) throws Exception {
        String sql="delete from t_user_car where id=?";
        return JDBCUtils.update(sql,id);

    }

    @Override
    public int update(UserCar userCar) throws Exception {
        String sql="update t_user_car set user_id=?,car_id=? where id=?";
        return JDBCUtils.update(sql,userCar.getCarId(),userCar.getUserId(),userCar.getId());
    }

    @Override
    public UserCar queryById(int id) throws Exception {
        String sql="select * from t_user_car where id=?";
        return JDBCUtils.query(sql,UserCar.class,id);
    }

    @Override
    public List<UserCar> queryAll() throws Exception {
        String sql="select * from t_user_car";
        return JDBCUtils.querylist(sql,UserCar.class);
    }
}
